home *** CD-ROM | disk | FTP | other *** search
Text File | 1995-11-08 | 12.5 KB | 403 lines | [TEXT/MPS ] |
- //========================================================================================
- //
- // File: FWSelect.cpp
- // Release Version: $ 1.0d11 $
- //
- // Copyright: © 1995 by Apple Computer, Inc., all rights reserved.
- //
- //========================================================================================
-
- #include "FWFrameW.hpp"
-
- #ifndef FWSELECT_H
- #include "FWSelect.h"
- #endif
-
- #ifndef FWUTIL_H
- #include "FWUtil.h"
- #endif
-
- #ifndef FWPRESEN_H
- #include "FWPresen.h"
- #endif
-
- #ifndef FWPART_H
- #include "FWPart.h"
- #endif
-
- #ifndef FWPRMISE_H
- #include "FWPrmise.h"
- #endif
-
- #ifndef FWCLNINF_H
- #include "FWClnInf.h"
- #endif
-
- #ifndef FWFRAME_H
- #include "FWFrame.h"
- #endif
-
- // ----- OS Layer Includes -----
-
- #ifndef FWODGEOM_H
- #include "FWODGeom.h"
- #endif
-
- #ifndef FWEVENT_H
- #include "FWEvent.h"
- #endif
-
- // ----- OpenDoc Includes -----
-
- #ifndef SOM_ODStorageUnit_xh
- #include <StorageU.xh>
- #endif
-
- #ifndef SOM_ODSession_xh
- #include <ODSessn.xh>
- #endif
-
- #ifndef SOM_ODClipboard_xh
- #include <Clipbd.xh>
- #endif
-
- #ifndef SOM_ODStorageUnitView_xh
- #include <SUView.xh>
- #endif
-
- #ifndef SOM_ODShape_xh
- #include <Shape.xh>
- #endif
-
- #ifndef SOM_ODFacet_xh
- #include <Facet.xh>
- #endif
-
- #ifndef SOM_Module_OpenDoc_StdProps_defined
- #include <StdProps.xh>
- #endif
-
- //========================================================================================
- // RunTime Info
- //========================================================================================
-
- #if FW_LIB_EXPORT_PRAGMAS
- #pragma lib_export on
- #endif
-
- #ifdef FW_BUILD_MAC
- #pragma segment FWFrameworkSelection
- #endif
-
- FW_DEFINE_CLASS_M0(FW_CSelection)
-
- //========================================================================================
- // class FW_CSelection
- //========================================================================================
-
- //----------------------------------------------------------------------------------------
- // FW_CSelection::FW_CSelection
- //----------------------------------------------------------------------------------------
-
- FW_CSelection::FW_CSelection(Environment* ev, FW_Boolean allowPublish, FW_Boolean allowSubscribe) :
- fPresentation(NULL),
- fAllowPublish(allowPublish),
- fAllowSubscribe(allowSubscribe)
- {
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CSelection::~FW_CSelection
- //----------------------------------------------------------------------------------------
-
- FW_CSelection::~FW_CSelection()
- {
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CSelection::ClearSelection
- //----------------------------------------------------------------------------------------
-
- FW_Boolean FW_CSelection::ClearSelection(Environment* ev)
- {
- FW_UNUSED(ev);
-
- return FALSE;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CSelection::CreateSelectionFrameShape
- //----------------------------------------------------------------------------------------
-
- ODShape* FW_CSelection::CreateSelectionFrameShape(Environment* ev) const
- {
- return NULL;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CSelection::CreateSelectionOutline
- //----------------------------------------------------------------------------------------
- // By default just outline the shape returned by CreateSelectionShape
-
- ODShape* FW_CSelection::CreateSelectionOutline(Environment* ev, ODFacet* facet, FW_CFrame* frame) const
- {
- ODShape* outline = CreateSelectionShape(ev, facet, frame);
-
- if (!outline->IsEmpty(ev))
- ::FW_OutlineODShape(ev, outline, FW_IntToFixed(1));
-
- return outline;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CSelection::IsSelectionPublishable
- //----------------------------------------------------------------------------------------
-
- FW_Boolean FW_CSelection::IsSelectionPublishable(Environment* ev)
- {
- return fAllowPublish;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CSelection::NewPromise
- //----------------------------------------------------------------------------------------
-
- FW_CPromise* FW_CSelection::NewPromise(Environment* ev,
- ODUpdateID updateID,
- FW_EStorageKinds storageKind,
- FW_CFrame* scopeFrame,
- ODCloneKind cloneKind)
- {
- return NULL;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CSelection::DoExternalizeSelection
- //----------------------------------------------------------------------------------------
-
- void FW_CSelection::DoExternalizeSelection(Environment* ev,
- ODStorageUnit* destinationSU,
- FW_CCloneInfo* cloneInfo)
- {
- FW_DEBUG_MESSAGE("FW_CSelection::DoExternalizeSelection should never be called");
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CSelection::PrivHandleExternalizeSelection
- //----------------------------------------------------------------------------------------
-
- void FW_CSelection::PrivHandleExternalizeSelection(Environment* ev,
- FW_EStorageKinds storageKind,
- ODStorageUnit* destinationSU,
- FW_CCloneInfo* cloneInfo)
- {
- // ----- Add the needed properties first -----
- GetPart(ev)->AddProperties(ev, destinationSU);
-
- ODUpdateID updateID = 0;
-
- GetPart(ev)->DeletePromise(ev, storageKind);
-
- if (storageKind == FW_kClipboardStorage)
- updateID = GetSession(ev)->GetClipboard(ev)->GetUpdateID(ev);
-
- FW_CPromise* promise = NewPromise(ev, updateID, storageKind, cloneInfo->GetScopeFrame(ev), cloneInfo->GetCloneKind(ev));
-
- if (promise)
- {
- GetPart(ev)->SetPromise(ev, promise);
- promise->PromisePropertiesAndValues(ev, destinationSU);
- }
- else
- {
- this->DoExternalizeSelection(ev, destinationSU, cloneInfo);
- }
-
- // ----- If supported, write a shape property -----
- FW_CAcquiredODShape aqSelectionShape = CreateSelectionFrameShape(ev);
- if (((ODShape*)aqSelectionShape) != NULL)
- {
- // ----- Add the property. WriteShape will add the value
- if (destinationSU->Exists(ev, kODPropFrameShape, (ODValueType)NULL, 0))
- {
- destinationSU->Focus(ev, kODPropFrameShape,
- kODPosUndefined,
- (ODValueType)NULL,
- (ODValueIndex)1,
- kODPosUndefined);
- destinationSU->Remove(ev); // remove the first value
- }
- else
- destinationSU->AddProperty(ev, kODPropFrameShape);
-
- aqSelectionShape->WriteShape(ev, destinationSU);
- }
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CSelection::PrivHandleInternalizeSelection
- //----------------------------------------------------------------------------------------
-
- FW_EInternalizeResult FW_CSelection::PrivHandleInternalizeSelection(Environment* ev,
- ODStorageUnit* sourceSU,
- FW_CCloneInfo* cloneInfo)
- {
- FW_Boolean result = this->DoInternalizeSelection(ev, sourceSU, cloneInfo);
- return result ? FW_kInternalizeContent : FW_kInternalizeFailed;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CSelection::PrivPostInternalizeSelection
- //----------------------------------------------------------------------------------------
-
- void FW_CSelection::PrivPostInternalizeSelection(Environment* ev,
- FW_CCloneInfo* cloneInfo,
- FW_EInternalizeResult result)
- {
- FW_UNUSED(ev);
- FW_UNUSED(result);
- FW_UNUSED(cloneInfo);
-
- // Nothing to do
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CSelection::GetPart
- //----------------------------------------------------------------------------------------
-
- FW_CPart* FW_CSelection::GetPart(Environment *ev) const
- {
- return GetPresentation(ev)->GetPart(ev);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CSelection::GetSession
- //----------------------------------------------------------------------------------------
-
- ODSession* FW_CSelection::GetSession(Environment *ev) const
- {
- return GetPart(ev)->GetSession(ev);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CSelection::IsMouseInDraggableItem
- //----------------------------------------------------------------------------------------
-
- FW_Boolean FW_CSelection::IsMouseInDraggableItem(Environment* ev, FW_CFrame* frame, const FW_CMouseEvent& theMouseEvent, FW_Boolean inBackground) const
- {
- if (IsEmpty(ev))
- return FALSE;
-
- FW_CAcquiredODShape selectionShape = CreateSelectionShape(ev, theMouseEvent.GetFacet(ev), frame);
-
- FW_CPoint where = theMouseEvent.GetMousePosition(ev, FW_CMouseEvent::kFrame);
- frame->GetContentView(ev)->FrameToViewContent(ev, where);
-
- ODPoint odWhere = where;
- return selectionShape->ContainsPoint(ev, &odWhere);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CSelection::UpdateSelectionOnMouseDown
- //----------------------------------------------------------------------------------------
-
- void FW_CSelection::UpdateSelectionOnMouseDown(Environment* ev,
- const FW_CMouseEvent& mouseEvent,
- ODFacet* embeddedFacet,
- FW_Boolean inEmbeddedFrameBorder,
- FW_Boolean inBackground)
- {
- // Don't do anything
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CSelection::CreateSelectionShape
- //----------------------------------------------------------------------------------------
-
- ODShape* FW_CSelection::CreateSelectionShape(Environment* ev, ODFacet* facet, FW_CFrame* frame) const
- {
- return ::FW_CopyAndRelease(ev, facet->AcquireActiveShape(ev, NULL));
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CSelection::CanSubscribe
- //--------------------------------------------------------------------
- FW_Boolean FW_CSelection::CanSubscribe(Environment* ev, ODPasteAsMergeSetting& setting)
- {
- // Override to allow this selection to become a destination link.
- // Also specify default settings for the PasteAs dialog:
- // kODPasteAsMergeOnly, kODPasteAsEmbedOnly, kODPasteAsMerge, kODPasteAsEmbed
- setting = kODPasteAsMergeOnly; // default is no embedding
-
- return fAllowSubscribe;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CSelection::DoFindPublisher
- //--------------------------------------------------------------------
- FW_CPublishLink* FW_CSelection::DoFindPublisher(Environment* ev)
- {
- // Override to search for a publisher that publishes this selection
- return NULL;
- }
-
- //---------------------------------------------------------------------------------------
- // FW_CSelection::InternalizeData
- //---------------------------------------------------------------------------------------
- // Note: Even if I am not an embedding part I still need to call BeginClone/EndClone
- // otherwise the OpernDoc's OriginaleCloneKind property in the draft is not set correctly
-
- FW_EInternalizeResult FW_CSelection::InternalizeData(Environment* ev,
- FW_CFrame* scopeFrame,
- ODStorageUnit* sourceSU,
- ODCloneKind cloneKind)
- {
- ODDraft* fromDraft = sourceSU->GetDraft(ev);
- ODDraft* dstDraft = GetPart(ev)->GetStorageUnit(ev)->GetDraft(ev);
-
- FW_EInternalizeResult result = FW_kInternalizeFailed;
-
- FW_CCloneInfo cloneInfo(ev, fromDraft, scopeFrame, cloneKind);
-
- cloneInfo.BeginClone(ev, dstDraft);
-
- result = PrivHandleInternalizeSelection(ev, sourceSU, &cloneInfo);
-
- if (result == FW_kInternalizeFailed)
- {
- cloneInfo.AbortClone(ev);
- return result;
- }
-
- cloneInfo.EndClone(ev);
-
- PrivPostInternalizeSelection(ev, &cloneInfo, result);
-
- return result;
- }
-
- //---------------------------------------------------------------------------------------
- // FW_CSelection::ExternalizeData
- //---------------------------------------------------------------------------------------
- // Note: Even if I am not an embedding part I still need to call BeginClone/EndClone
- // otherwise the OpernDoc's OriginaleCloneKind property in the draft is not set correctly
-
- void FW_CSelection::ExternalizeData(Environment* ev,
- FW_CFrame* scopeFrame,
- FW_EStorageKinds storageKind,
- ODStorageUnit* destinationSU,
- ODCloneKind cloneKind)
- {
- ODDraft* fromDraft = GetPart(ev)->GetStorageUnit(ev)->GetDraft(ev);
- ODDraft* dstDraft = destinationSU->GetDraft(ev);
-
- FW_CCloneInfo cloneInfo(ev, fromDraft, scopeFrame, cloneKind);
-
- cloneInfo.BeginClone(ev, dstDraft);
-
- PrivHandleExternalizeSelection(ev, storageKind, destinationSU, &cloneInfo);
-
- cloneInfo.EndClone(ev);
- }
-
-